/**
 * 设计一的主程序
*/
#include "commutils.h"

//当前工作目录
vector<folderiNode> workpath;
//用户输入的指令及参数
vector<string> cmdv;
//用户id，默认-1表示空
int userid = -1;
//是否第一次循环
bool firsttime = true;

/**
 * 主函数，程序入口
*/
int main(int argc, char *argv[])
{
    string cmdstr, line;
    showTitle();
    loadBitMap();
    userid = login();
    workpath.push_back(readFolderInode(0));
    while (1)
    {
        //打印当前工作目录
        printPath(workpath);
        //除去多余的一行
        if (firsttime)
        {
            getline(cin, line);
            firsttime = false;
        }
        //读取输入
        getline(cin, line);
        //判断输入是否为空
        if (line.empty())
        {
            cout << usage_input;
            continue;
        }
        //清空命令向量
        cmdv.clear();
        //分割整行命令
        SplitString(line, cmdv, " ");
        cmdstr = cmdv[0];
        //判断命令并执行
        if (!cmdstr.compare("info"))
        {
            DiskStatus ds = getDiskStatus();
            cout << ds.toString();
        }
        else if (!cmdstr.compare("copy"))
        {
            doCopy(cmdv, workpath, userid);
        }
        else if (!cmdstr.compare("rd"))
        {
            doRd(cmdv, workpath, userid);
        }
        else if (!cmdstr.compare("del"))
        {
            doDel(cmdv, workpath, userid);
        }
        else if (!cmdstr.compare("newfile"))
        {
            doNewfile(cmdv, workpath, userid);
        }
        else if (!cmdstr.compare("cd"))
        {
            doCd(cmdv, workpath, userid);
        }
        else if (!cmdstr.compare("cat"))
        {
            doCat(cmdv, workpath, userid);
        }
        else if (!cmdstr.compare("dir"))
        {
            doDir(cmdv, workpath, userid);
        }
        else if (!cmdstr.compare("md"))
        {
            doMd(cmdv, workpath, userid);
        }
        else if (!cmdstr.compare("format"))
        {
            doFormat(cmdv, workpath, userid);
        }
        else if (!cmdstr.compare("check"))
        {
            doCheck(cmdv, workpath, userid);
        }
        else if (!cmdstr.compare("fcy"))
        {
            cout << "FCY is a nice guy.\n";
        }
        else if (!cmdstr.compare("exit"))
        {
            cout << "bye.\n";
            exit(0);
        }
        else
        {
            cout << "command error! try again.\n";
        }
    }
    exit(0);
}